@extends('Admin.layout.layout')
@section('content')
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>资质管理</h5>
                    </div>
                    <div class="ibox-content">
                        <div class="tabs-container">
                            <ul class="nav nav-tabs" id="navState">
                                <li data-id=""><a data-toggle="tab" aria-expanded="true">全部</a>
                                </li>
                                <li class="" data-id="0"><a data-toggle="tab" aria-expanded="true">已审核</a>
                                </li>
                                <li class="" data-id="1"><a data-toggle="tab" aria-expanded="true">待审核</a>
                                </li>
                            </ul>
                            <div class="tab-content">
                                <div id="tab-1" class="tab-pane active">
                                    <div class="panel-body">
                                        <div class="row">
                                            <form action="" method="GET">
                                                <div class="col-sm-12">
                                                    <a href="aptitude/add" class="btn btn-sm btn-primary">新增</a>
                                                    <button type="submit" class="btn btn-sm btn-primary fr"> 搜索</button>
                                                    <div class="input-group fr10">
                                                        <input type="text" placeholder="请输入资质名称" class="input-sm form-control" name="value" value="">
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                        <table class="table table-striped table-bordered table-hover dataTable" id="editable">
                                            <thead>
                                                <tr>
                                                    <th class="center">ID</th>
                                                    <th class="center" width="400">资质名称</th>
                                                    <th class="center" width="300">级别</th>
                                                    <th class="center">状态</th>
                                                    <th class="center">更新时间</th>
                                                    <th class="center">操作</th>
                                                </tr>
                                            </thead>
                                            <tbody>

                                                <tr>
                                                    <td class="center">15201</td>
                                                    <td class="center">信息系统集成与服务资质信息系统集成与服务资质信息系统集成与服务资质信息系统集成与服务资质</td>
                                                    <td class="center">
                                                        <p>
                                                            <font>一级</font>
                                                        </p>
                                                        <p>
                                                            <font>二级</font>
                                                        </p>
                                                        <p>
                                                            <font>三级</font>
                                                        </p>
                                                        <div class="btn btn-warning btn-xs add_level_btn" data-id="1">新增级别</div>
                                                        <div class="add_level" style="display: none;">
                                                            <input style="width: 150px;display: inline-block;" class="input-sm form-control" type="text" value="">
                                                            <div class="btn btn-primary btn-xs ensure_level_btn" data-id="1">确定</div>
                                                            <div class="btn btn-default btn-xs cancel_level_btn" data-id="1">取消</div>
                                                        </div>
                                                    </td>
                                                    <td class="center">
                                                        已审核
                                                    </td>
                                                    <td class="center">
                                                        2018/02/07
                                                    </td>
                                                    <td class="center">
                                                        <select   data-id="1" style="margin-right: 10px;" class="status_search">
                                                            <option value="0">未审核</option>
                                                            <option value="1">已审核</option>
                                                            <option value="2">未通过</option>
                                                        </select>
                                                        <a class="btn-xs btn-primary" data-id="1" href="aptitude/eidt/1">编辑</a>
                                                        <a class="btn-xs btn-danger cancel_btn" data-id="1">删除</a>
                                                    </td>
                                                </tr>

                                                <tr class="no-records-found center"><td colspan="8">没有找到匹配的记录</td></tr>

                                            </tbody>
                                        </table>
                                        <div class="row">
                                            include('Admin.common.paginate')
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="{{asset('js/plugins/layer/layer.min.js')}}"></script>
    <script>

        $(document).ready(function () {
            $.getUrlParam = function(name)
            {
             var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
             var r = window.location.search.substr(1).match(reg);
             if (r!=null) return unescape(r[2]); return null;
            }
            var status=$.getUrlParam('status');
            if(status == '' || !status){
                $('#navState li').eq(0).addClass('active');
            }else if(status == 0){
                $('#navState li').eq(1).addClass('active');
            }else if(status == 1){
                $('#navState li').eq(2).addClass('active');
            }

            $("#navState li").on('click', function (event) {
                event.preventDefault();
                $("#navState li").removeClass('active');
                $(this).addClass('active');
                var state = $(this).attr('data-id');
                location.href = 'aptitude?status=' + state;
            });


            //新增级别
            $(document).on('click', '.add_level_btn', function (event) {
                $(this).next('.add_level').show();
            })
            //确定新增级别
            $(document).on('click', '.ensure_level_btn', function (event) {
                var level_val = $(this).prev().val();
                var id = $(this).attr('data-id');
                $.ajax({
                    url: "",
                    type: 'put',
                    dataType: 'json',
                    data: {'level_val': level_val},
                    success: function (data) {
                        if (0 == data.code) {
                           location.reload();
                        } else {
                            layer.alert(data.message, {
                                icon: 2
                            });
                        }
                    }
                });
            })
            //取消新增级别
            $(document).on('click', '.cancel_level_btn', function (event) {
                $(this).parent('.add_level').hide();
                $(this).prev().prev().val('');
            })

            //审核
            $(".status_search").change(function(){
                edit_id = $(this).attr("data-id");//编辑时属性的id
                var status_val = $(this).val();
                $.ajax({
                    url: "",
                    type: 'put',
                    dataType: 'json',
                    data: {'status': status_val},
                    success: function (data) {
                        if (0 == data.code) {
                           location.reload();
                        } else {
                            layer.alert(data.message, {
                                icon: 2
                            });
                        }
                    }
                });
            });
            //删除
            $('.cancel_btn').click(function(){
                var order_id = $(this).attr('data-id');
                layer.confirm('是否删除？', {
                    btn: ['确认', '取消'] //可以无限个按钮
                }, function (index) {
                    $.ajax({
                        url: '',
                        type: 'PUT',
                        dataType: 'json',
                        data: {},
                        success: function (data) {
                            if (0 == data.code) {
                                layer.alert(data.message, {
                                    icon: 1
                                }, function () {
                                    location.reload();
                                });
                            } else {
                                layer.alert(data.message, {
                                    icon: 2
                                });
                            }
                        },
                    });
                }, function (index, layero) {
                    layer.close(index);
                });
            })

        });
    </script>
@endsection
